package com.cwd.arm.common.util;

/**
 * Created by yan on 21-12-26.
 */
public class SqlUtil {

    /**
     * java属性转数据库字段
     *
     * @param voName
     * @return
     */
    public static String toColumn(String voName) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < voName.length(); i++) {
            char cur = voName.charAt(i);
            if (Character.isUpperCase(cur)) {
                sb.append("_");
                sb.append(cur);
            } else {
                sb.append(cur);
            }
        }
        return sb.toString().toUpperCase();
    }


    /**
     * 数据库字段转java属性
     *
     * @param voName
     * @return
     */
    public static String toField(String voName) {
        StringBuffer sb = new StringBuffer();
        boolean flag = false;
        for (int i = 0; i < voName.length(); i++) {
            char cur = voName.charAt(i);
            if (cur == '_') {
                flag = true;

            } else {
                if (flag) {
                    sb.append(Character.toUpperCase(cur));
                    flag = false;
                } else {
                    sb.append(Character.toLowerCase(cur));

                }

            }
        }
        return sb.toString();
    }



}
